#include "FiveWin.ch"

//----------------------------------------------------------------------------//

CLASS TFont

   DATA   cFaceName
   DATA   hFont, hFontOld
   DATA   lItalic, lUnderline, lStrikeOut
   DATA   nHeight, nWidth, nEscapement, nOrientation, nWeight
   DATA   nCharSet, nOutPrecision, nClipPrecision, nQuality, nPitchFamily

   METHOD New( cFaceName, nWidth, nHeight, lFromUser, nEscapement,;
              nOrientation, nWeight, lItalic, lUnderline, lStrikeOut,;
              nCharSet, nOutPrecision, nClipPrecision, nQuality ) CONSTRUCTOR
   METHOD Choose() VIRTUAL
   METHOD Release()         BLOCK ;
              { | Self | DeleteObject( ::hFont ) }

   METHOD Activate( hDC )   BLOCK ;
              { | Self, hDC | ::hFontOld := SelectObject( hDC, ::hFont ) }

   METHOD DeActivate( hDC ) BLOCK ;
              { | Self, hDC | SelectObject( hDC, ::hFontOld ) }

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cFaceName, nWidth, nHeight, lFromUser, nEscapement, nOrientation,;
            nWeight, lItalic, lUnderline, lStrikeOut, nCharSet,;
            nOutPrecision, nClipPrecision, nQuality ) CLASS TFont

   local aFont

   DEFAULT nEscapement := 0, nOrientation := 0, nWeight := 0, lItalic := .f.,;
           lFromUser := .f., lUnderLine := .f., lStrikeOut := .f.,;
           nCharSet := 0, nOutPrecision := 0, nClipPrecision := 0,;
           nQuality := 0

   if lFromUser
      aFont     = ChooseFont()
      lFromUser = ! Empty( aFont[ LF_FACENAME ] )
      Alert( "Width:" + Str( aFont[ LF_WIDTH ] ) )
      Alert( "Height:" + Str( aFont[ LF_HEIGHT ] ) )
      Alert( "Name:" + aFont[ LF_FACENAME ] )
   endif

   ::cFaceName      = If( lFromUser, aFont[ LF_FACENAME ], cFaceName )
   ::nHeight        = If( lFromUser, aFont[ LF_HEIGHT ], nHeight )
   ::nWidth         = If( lFromUser, aFont[ LF_WIDTH ], nWidth )
   ::nEscapement    = If( lFromUser, aFont[ LF_ESCAPEMENT ], nEscapement )
   ::nOrientation   = If( lFromUser, aFont[ LF_ORIENTATION ], nOrientation )
   ::nWeight        = If( lFromUser, aFont[ LF_WEIGHT ], nWeight )
   ::lItalic        = If( lFromUser, aFont[ LF_ITALIC ], lItalic )
   ::lUnderLine     = If( lFromUser, aFont[ LF_UNDERLINE ], lUnderLine )
   ::lStrikeOut     = If( lFromUser, aFont[ LF_STRIKEOUT ], lStrikeOut )
   ::nCharSet       = If( lFromUser, aFont[ LF_CHARSET ], nCharSet )
   ::nOutPrecision  = If( lFromUser, aFont[ LF_OUTPRECISION ], nOutPrecision )
   ::nClipPrecision = If( lFromUser, aFont[ LF_CLIPPRECISION ], nClipPrecision )
   ::nQuality       = If( lFromUser, aFont[ LF_QUALITY ], nQuality )
   ::hFontOld       = 0

   if ::cFaceName != "System"
      ::hFont = CreateFont( { ::nHeight, ::nWidth, ::nEscapement,;
                              ::nOrientation, ::nWeight, ::lItalic,;
                              ::lUnderLine, ::lStrikeOut, ::nCharSet,;
                              ::nOutPrecision, ::nClipPrecision,;
                              ::nQuality, ::nPitchFamily, ::cFaceName } )
   endif

return

//----------------------------------------------------------------------------//
